package cn.edu.cug.springwebdemo.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {
    private static final Logger logger = LoggerFactory.getLogger(HelloController.class);

    @RequestMapping("/")
    public String index(){
        return "index";
    }

    @RequestMapping("/hello")
    @ResponseBody
    // 注意 ResponseBody标注的入口，其返回的结果直接写入
    public String hello(){
        return "Hello Gradle.";
    }

    @RequestMapping(value = "/thymelaf")
    public String themelafDemo(Model model){
        model.addAttribute("message", "This is an test for Thymelaf.");
        logger.info("themelafDemo called.");
        return "index";
    }

    @RequestMapping(value = "/variaTest")
    public String variaTest(@RequestParam("name") String userName, Model model){
        model.addAttribute("message", "The man whose name is "+userName+" called this method");
        return "index";
    }

}
